<?php ob_start();?>
<html>
<?php 
	$root = $_SERVER['DOCUMENT_ROOT'];
 	include($root.'/standart/head.php');
 	include($root.'/standart/dateHeader.php');
 	include($root.'/standart/checkUser.php');
?>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Start Bootstrap - SB Admin Version 2.0 Demo</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="../css/sb-admin.css" rel="stylesheet">
    <link href="../css/tinyBox.css" rel="stylesheet" type="text/css" media="screen"/>
    <link href="../css/jquery-ui-1.10.4.css" rel="stylesheet" type="text/css" media="screen"/>
	<link href="../css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <script type="text/javascript">
    	function getInventoryList() {
			url = 'setInventory.php?onlyId';
			$('#selectBox').html(ajx(url, ''));
		}
		<?php 
		$ten_days = time( ) - 86400 * 30;
		$days_ago = date("d/m/Y", $ten_days);
		?>
		var defDate = "<?php echo date('d/m/Y', time());?>";
		var agoDate = "<?php echo $days_ago;?>";
		function loadPage() {
			getInventoryList();
			$('#invoice_bgn_date').val(agoDate);
			$('#invoice_end_date').val(defDate);
			$('.datepicker').datepicker();
			listMaterials();
// 			parent.unloadPageX();
		}

		function listMaterials(){
			parent.loadPageX(); 
			url = 'getMaterials.php?report=1'
				+'&begin_date='+$("#invoice_bgn_date").val()
				+'&end_date='+$("#invoice_end_date").val()
				+'&inventory='+$("#selectBox").val()
				+'&invoice_no='+$("#search_invoice_no").val();
			ajx(url, 'endOfListMaterials');
// 			var table = $('#dataTables-example').dataTable({
// 	            "language": {
// 	                "url": "../css/plugins/dataTables/dataTablesTurkish.json"
// 	            },
// 				"footerCallback": function ( row, data, start, end, display ) {
// 		            var api = this.api();
// 		            // Remove the formatting to get integer data for summation
// 		            var intVal = function ( i ) {
// 		                return typeof i === 'string' ?
// 		                    i.replace(/[\$,]/g, '')*1 :
// 		                    typeof i === 'number' ?
// 		                        i : 0;
// 		            };
		 
// 		            // Total over all pages
// 		            var total = api
// 		                .column( 9 )
// 		                .data()
// 		                .reduce( function (a, b) {
// 		                    return intVal(a) + intVal(b);
// 		                } );
		 
// 		            // Total over this page
// 		            var pageTotal = api
// 		                .column( 9, { page: 'current'} )
// 		                .data()
// 		                .reduce( function (a, b) {
// 		                    return intVal(a) + intVal(b);
// 		                } );
		 
// 		            // Update footer
// 		            $( api.column( 9 ).footer() ).html(
// 		                ''+pageTotal.toFixed(2) +'TL ( '+ total.toFixed(2) +' TL toplam)'
// 		            );
// 		        }
// 	        } );

// 			getPie();
// 			parent.unloadPageX();
		}

		function endOfListMaterials(_htm){
			$('.table-responsive').html(_htm);
			var table = $('#dataTables-example').dataTable({
	            "language": {
	                "url": "../css/plugins/dataTables/dataTablesTurkish.json"
	            },
				"footerCallback": function ( row, data, start, end, display ) {
		            var api = this.api();
		            // Remove the formatting to get integer data for summation
		            var intVal = function ( i ) {
		                return typeof i === 'string' ?
		                    i.replace(/[\$,]/g, '')*1 :
		                    typeof i === 'number' ?
		                        i : 0;
		            };
		 
		            // Total over all pages
		            var total = api
		                .column( 9 )
		                .data()
		                .reduce( function (a, b) {
		                    return intVal(a) + intVal(b);
		                } );
		 
		            // Total over this page
		            var pageTotal = api
		                .column( 9, { page: 'current'} )
		                .data()
		                .reduce( function (a, b) {
		                    return intVal(a) + intVal(b);
		                } );
		 
		            // Update footer
		            $( api.column( 9 ).footer() ).html(
		                ''+pageTotal.toFixed(2) +'TL ( '+ total.toFixed(2) +' TL toplam)'
		            );
		        }
	        } );

			getPie();
			parent.unloadPageX();
		}

		function getPie(){
			url = 'getMaterialsPie.php?'
				+'begin_date='+$("#invoice_bgn_date").val()
				+'&end_date='+$("#invoice_end_date").val()
				+'&inventory='+$("#selectBox").val()
				+'&invoice_no='+$("#search_invoice_no").val();
			document.getElementById('container').src = url;
		}
    </script>
</head>

<body onload="loadPage()">
    <div id="wrapper">
        <div id="inner-page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">Malzeme Girişi Raporu</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <!-- /.col-lg-12 -->
                <div class="col-lg-12">
                	<div class="panel panel-default">
                        <div class="panel-body">
                        	<div class="row">
                                <div class="col-lg-12">
                                	<div class="form-group" style="float: left; margin-right: 20px;">
										<label style="margin-top: 7px;">Malzeme Türü</label>
									</div>
                                	<div class="form-group" style="float: left;  margin-right: 20px;">
                                        <select class="form-control" id="selectBox" name="selectBox">
                                        </select>
									</div>
                                	<div class="form-group" style="float: left; margin-right: 20px;">
										<label style="margin-top: 7px;">Başlangıç Fatura Tarihi</label>
									</div>
                                	<div class="form-group" style="float: left;  margin-right: 20px;">
                                        <input type="text" class="form-control datepicker" id="invoice_bgn_date">
									</div>
                                	<div class="form-group" style="float: left;  margin-right: 20px;">
										<label style="margin-top: 7px;">Bitiş Fatura Tarihi</label>
									</div>
                                	<div class="form-group" style="float: left;  margin-right: 20px;">
                                        <input type="text" class="form-control datepicker" id="invoice_end_date">
									</div>
                                	<div class="form-group" style="float: left;  margin-right: 20px;">
										<label style="margin-top: 7px;">Fatura No</label>
									</div>
                                	<div class="form-group" style="float: left;  margin-right: 20px;">
                                        <input type="text" class="form-control" id="search_invoice_no">
									</div>
                                	<button type="button" id="btnGetHtml" class="btn btn-default" onclick="listMaterials()">Listele</button>
                                </div>
                            </div>
                        	<div class="table-responsive">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
				<div class="col-lg-6" style="height: 450px;">
		            <iframe frameborder="0" class="frame" src="" id="container"></iframe>
				</div>
			</div>
            <!-- /.row -->
        </div>
        <!-- /#page-wrapper -->
		
    </div>
    <!-- /#wrapper -->
    <!-- Core Scripts - Include with every page -->
    <!-- Page-Level Demo Scripts - Forms - Use for reference -->
</body>
    <script type="text/javascript" src="../js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="../js/ajax.js"></script>
    <script type="text/javascript" src="../js/tinybox.js"></script>
    <script type="text/javascript" src="../js/jquery-ui-1.10.4.js"></script>
    <script type="text/javascript" src="../js/plugins/dataTables/jquery.dataTables.js"></script>
    <script type="text/javascript" src="../js/plugins/dataTables/dataTables.bootstrap.js"></script>
</html>
<?php ob_end_flush(); ?>